<template>
  <div class="pageB">
    <div>
      <el-button @click="goback">返回</el-button>
    </div>
    <el-input v-model="sum" style="width: 200px;"></el-input>
    <el-button type="primary" @click="handleSum1">+1</el-button>
    <br><br>
    <span class="storesum">{{ storesum }}</span>
    <el-button type="primary" @click="add">+2</el-button>
    <el-button @click="reduce">-2</el-button>
  </div>
</template>

<script>
import { EventBus } from '@/common/event-bus';
// 引入组件
import { Button, Input } from 'element-ui';
export default {
  name:"pageB",
  components: {
    // 注册组件
    'el-button': Button,
    'el-input': Input
  },
  data() {
    return {
      sum:0
    }
  },
  computed:{
    storesum(){
      return this.$store.state.sum
    },
  },
  mounted(){
    // EventBus.$off('getMsg');//先解绑后绑定，防止多触发事件
    EventBus.$on('getMsg',(msg)=>{
      this.getMsg(msg)
    })
  },
  methods:{
    getMsg(msg){
      console.log('接受消息',msg);
    },
    handleSum1(){
      this.sum++;
    },
    add(){
      this.$store.commit('add',2);
    },
    reduce(){
      this.$store.commit('reduce',2);
    },
    goback(){
      this.$router.back();
    }
  }
}
</script>

<style scoped>
.pageB{
  width: 500px;
  margin: 30px auto;
  text-align: left;
}
.storesum{
  width: 200px;
  -webkit-appearance: none;
  background-color: #FFF;
  background-image: none;
  border-radius: 4px;
  border: 1px solid #DCDFE6;
  box-sizing: border-box;
  color: #606266;
  display: inline-block;
  height: 40px;
  line-height: 40px;
  outline: 0;
  padding: 0 15px;
}
</style>